<template>
  <section>
    <van-sticky>
      <PageHeader title="营销活动/参与人" />
    </van-sticky>

    <van-list
      class="mt10"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestList">
      <div class="flex flex-col bg-color-white mb10 font-common"
           v-for="(item, index) in dataList"
           :key="index">
        <div class="flex flex-row flex-left flex-centerV pd10">
          <img :src="item.user.avatar_url ? item.user.avatar_url : BASE_STATIC_URL + 'images/mp/avatar.jpeg'" class="user-avatar" />
          <span class="ml5">{{item.user.nick}}</span>
        </div>
        <div class="flex flex-row flex-left pd10">参与时间：{{item.join_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
      </div>
    </van-list>

  </section>
</template>

<script>
import PageHeader from "../../componets/PageHeader";
import {marketingActivityJoinerListsUri} from "../../../common/api";

export default {
  components: {
    PageHeader
  },
  data() {
    return {
      currentPage: 1,
      lastPage: 0,
      total: 0,
      pageSize: 10,
      loading: false,
      finished: false,
      dataList: [],
    }
  },
  methods: {
    requestList() {
      const that = this;
      this.loading = true;
      let url = marketingActivityJoinerListsUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage
          + '&activity_id=' + this.$route.params.activity_id;
      this.$http.get(url).then(response => {
        let {code, msg, data} = response.body
        if (code != 0) {
          that.toast.fail(msg);
        } else {
          that.loading = false;
          if (that.currentPage >= data.last_page) {
            that.finished = true;
          }
          that.currentPage = that.currentPage + 1;
          for (let i = 0; i < data.data.length; i++) {
            that.dataList.push(data.data[i]);
          }
          that.total = data.total;
          that.lastPage = data.last_page;
        }
      }, response => {
        // error callback
      })
    },
  },
  mounted: function () {

  }
}
</script>

<style scoped>
.user-avatar {
  height: 30px;
  width: 30px;
  border-radius: 15px;
}
</style>
